package com.liuchuanzheng.lcz_study_demo

import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.liuchuanzheng.lcz_study_demo.behavior.Behavior2Activity
import com.liuchuanzheng.lcz_study_demo.behavior.BehaviorActivity
import com.liuchuanzheng.lcz_study_demo.databinding.ActivityMainBinding
import com.liuchuanzheng.lcz_study_demo.hook.HookActivity
import com.liuchuanzheng.lcz_study_demo.motionLayout.MotionLayout2Activity
import com.liuchuanzheng.lcz_study_demo.motionLayout.MotionLayout3Activity
import com.liuchuanzheng.lcz_study_demo.motionLayout.MotionLayoutActivity
import com.liuchuanzheng.lcz_study_demo.room.RoomActivity

class MainActivity : AppCompatActivity() {
    lateinit var mViewBinding: ActivityMainBinding
    val adapter: MyAdapter by lazy { MyAdapter(null) }
    val mutableList:MutableList<FunctionBean> = mutableListOf()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mViewBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(mViewBinding.root)
        mViewBinding.recyclerView.setLayoutManager(LinearLayoutManager(this))
        mViewBinding.recyclerView.adapter = adapter
        initData()
        adapter.setOnItemClickListener { adapter, view, position ->
            var get = mutableList.get(position)
            startActivity(Intent(this@MainActivity,get.clazz))
        }
        adapter.setNewInstance(mutableList)

    }

    private fun initData() {
        mutableList.add(FunctionBean("behavior嵌套滑动", BehaviorActivity::class.java))
        mutableList.add(FunctionBean("behavior依赖", Behavior2Activity::class.java))
        mutableList.add(FunctionBean("motionlayout", MotionLayoutActivity::class.java))
        mutableList.add(FunctionBean("motionlayout多个", MotionLayout2Activity::class.java))
        mutableList.add(FunctionBean("motionlayout播放器", MotionLayout3Activity::class.java))
        mutableList.add(FunctionBean("hook", HookActivity::class.java))
        mutableList.add(FunctionBean("room", RoomActivity::class.java))
    }

    inner class MyAdapter(data: MutableList<FunctionBean>?): BaseQuickAdapter<FunctionBean, BaseViewHolder>(R.layout.rv_item,data) {
        /**
         * Implement this method and use the helper to adapt the view to the given item.
         *
         * 实现此方法，并使用 helper 完成 item 视图的操作
         *
         * @param helper A fully initialized helper.
         * @param item   The item that needs to be displayed.
         */
        override fun convert(holder: BaseViewHolder, item: FunctionBean) {
            holder.setText(R.id.tv_name,item.name)
        }

    }
    data class FunctionBean(var name: String,var clazz: Class<*>)
}